package es.cazadoresmadridejos.web.decorator;

import java.util.Calendar;
import java.util.Date;

import javax.servlet.jsp.PageContext;

import org.displaytag.decorator.DisplaytagColumnDecorator;
import org.displaytag.exception.DecoratorException;
import org.displaytag.properties.MediaTypeEnum;

import es.cazadoresmadridejos.util.constants.Constants;

public class DateDecorator implements DisplaytagColumnDecorator{


	@Override
	public Object decorate(Object columnValue, PageContext pageContext,
			MediaTypeEnum media) throws DecoratorException {
		if(columnValue == null){
			return "";
		}
		return Constants.sdf.format(columnValue);
	}

	public static final String getDecoratedDate(Date date){
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		
		String day = getWeekDay(cal.get(Calendar.DAY_OF_WEEK));
		
		String monthDay = String.valueOf(cal.get(Calendar.DAY_OF_MONTH));

		return day + " " + monthDay + " " + getMonth(cal.get(Calendar.MONTH)) + " de " + cal.get(Calendar.YEAR);
	}
	
	public static String getWeekDay(int day){
		switch (day) {
		case 1: return "Domingo";
		case 2: return "Lunes";
		case 3: return "Martes";
		case 4: return "Miércoles";
		case 5: return "Jueves";
		case 6: return "Viernes";
		case 7: return "Sábado";
		default: return "";
		}
	}
	
	public static String getMonth(int month){
		switch (month) {
		case 0: return "Enero";
		case 1: return "Febrero";
		case 2: return "Marzo";
		case 3: return "Abril";
		case 4: return "Mayo";
		case 5: return "Junio";
		case 6: return "Julio";
		case 7: return "Agosto";
		case 8: return "Septiembre";
		case 9: return "Octubre";
		case 10: return "Noviembre";
		case 11: return "Diciembre";
		default: return "";
		}
	}

}
